package top.rish.minfire;

import org.noear.solon.Solon;
import org.noear.solon.SolonProps;
import org.noear.solon.annotation.Controller;
import org.noear.solon.annotation.Inject;
import org.noear.solon.annotation.Mapping;
import org.noear.solon.annotation.Param;
import org.noear.solon.core.handle.Context;
import org.noear.solon.core.handle.ModelAndView;
import top.rish.minfire.config.AppCenterConfig;

@Controller
public class DemoController {

    @Inject
    AppCenterConfig appCenterConfig;

//    @Inject("${solon.staticfiles.mappings}")
//    List<Map<String,Object>> mappings;

    public ModelAndView index() throws Exception {
        return new ModelAndView("index.html").put("username","fwe");
    }

    @Mapping("/")
    public ModelAndView index_1() throws Throwable {
        return this.index();
    }

    @Mapping("/index")
    public ModelAndView index_2() throws Throwable {
        return this.index();
    }

    @Mapping("/index.html")
    public ModelAndView index_3() throws Throwable {
        return this.index();
    }

    @Mapping("/config")
    public void config(Context ctx) throws Throwable {
        SolonProps props = Solon.cfg().loadEnv("");
        ctx.outputAsJson(ctx.renderAndReturn(props));
    }

    @Mapping("/hello")
    public String hello(@Param(defaultValue = "world") String name) {
        return String.format("Hello %s!", name);
    }
    
    @Mapping("/hello2")
    public ModelAndView hello2(@Param(defaultValue = "world") String name) {
        return new ModelAndView("hello2.ftl").put("name", name);
    }
}